package com.google.zahra.soap.data.structs;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import javax.xml.bind.annotation.XmlType;

@XmlType(propOrder = {"urls", "id"})
public class ChromeBotWorkPacket implements Serializable {

  private static final long serialVersionUID = 5851281360851540839L;

  public String[] getUrls() {
    return this.urls;
  }

  public void setUrls(String[] urls) {
    this.urls = urls;
  }

  public String getId() {
    return this.id;
  }

  public void setId(String id) {
    this.id = id;
  }

  private String[] urls;
  private String id;
  

  public static byte[] getByteArray(final ChromeBotWorkPacket wp) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
      ObjectOutput out = new ObjectOutputStream(bos);
      out.writeObject(wp);
      out.close();

    } catch (IOException ex) {
      ex.printStackTrace();
    }
    return bos.toByteArray();
  }

  public static ChromeBotWorkPacket fromByteArray(final byte[] bytes) {

    if (bytes == null) {
      return null;
    }
    
    try {
      ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
      ChromeBotWorkPacket wp = (ChromeBotWorkPacket) in.readObject();
      in.close();
      return wp;
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    return null;
  }
}
